import { ref } from "vue"

export const registerUser = ref({
    account: "",
    companyName: "",
    password: "",
    password2: "",
});

const validatePass2 = (rule: any, value: any, callback: any) => {
    if (value === '') {
        callback(new Error('请再次输入密码'));
    } else if (value != registerUser.value.password) {
        callback(new Error('两次输入密码不一致'));
    } else {
        callback();
    }
}

export const registerRules = ref({
    account: [{ message: "账号不能为空", required: true, trigger: 'blur' },],
    companyName: [{ message: "公司名称不能为空", required: true, trigger: 'blur' },],
    password: [{ required: true, message: "密码不能为空", trigger: 'blur' },
    { min: 6, max: 30, message: "密码长度必须在6-30之间", trigger: 'blur' }],
    password2: [{ required: true, message: "密码不能为空", trigger: 'blur' },
    { min: 6, max: 30, message: "密码长度必须在6-30之间", trigger: 'blur' },
    { validator: validatePass2, trigger: 'blur' }],
})